package com.dianping.cat.configuration.web.url.transform;

import com.dianping.cat.configuration.web.url.IEntity;
import com.dianping.cat.configuration.web.url.IVisitor;
import com.dianping.cat.configuration.web.url.entity.Code;
import com.dianping.cat.configuration.web.url.entity.PatternItem;
import com.dianping.cat.configuration.web.url.entity.UrlPattern;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private UrlPattern m_urlPattern;


  public DefaultMerger() {}

  public DefaultMerger(UrlPattern urlPattern) {
/*  21 */     this.m_urlPattern = urlPattern;
/*  22 */     this.m_objs.push(urlPattern);
  }


/*  26 */   public UrlPattern getUrlPattern() { return this.m_urlPattern; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeCode(Code to, Code from) { to.mergeAttributes(from); }



/*  44 */   protected void mergePatternItem(PatternItem to, PatternItem from) { to.mergeAttributes(from); }



/*  48 */   protected void mergeUrlPattern(UrlPattern to, UrlPattern from) { to.mergeAttributes(from); }



  public void visitCode(Code from) {
/*  53 */     Code to = (Code)this.m_objs.peek();

/*  55 */     mergeCode(to, from);
/*  56 */     visitCodeChildren(to, from);
  }


  protected void visitCodeChildren(Code to, Code from) {}


  public void visitPatternItem(PatternItem from) {
/*  64 */     PatternItem to = (PatternItem)this.m_objs.peek();

/*  66 */     mergePatternItem(to, from);
/*  67 */     visitPatternItemChildren(to, from);
  }


  protected void visitPatternItemChildren(PatternItem to, PatternItem from) {}


  public void visitUrlPattern(UrlPattern from) {
/*  75 */     UrlPattern to = (UrlPattern)this.m_objs.peek();

/*  77 */     mergeUrlPattern(to, from);
    visitUrlPatternChildren(to, from);
  }

  protected void visitUrlPatternChildren(UrlPattern to, UrlPattern from) {
/*  82 */     for (PatternItem source : from.getPatternItems().values()) {
/*  83 */       PatternItem target = to.findPatternItem(source.getName());

/*  85 */       if (target == null) {
/*  86 */         target = new PatternItem(source.getName());
/*  87 */         to.addPatternItem(target);
      }

/*  90 */       this.m_objs.push(target);
/*  91 */       source.accept(this);
/*  92 */       this.m_objs.pop();
    }

/*  95 */     for (Code source : from.getCodes().values()) {
/*  96 */       Code target = to.findCode(source.getId());

/*  98 */       if (target == null) {
/*  99 */         target = new Code(source.getId());
/* 100 */         to.addCode(target);
      }

/* 103 */       this.m_objs.push(target);
/* 104 */       source.accept(this);
/* 105 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/web/url/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */